<template>
  <div>
    <article class="main-breadcrumb">
      <el-breadcrumb separator=">" class="main-breadcrumb-wrap">
        <el-breadcrumb-item>
          <span class="main-breadcrumb-home">排程管理</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <span class="main-breadcrumb-home" @click="$router.go(-1)">排程工具</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <span class="main-breadcrumb-home">排程预览</span>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </article>
    <div class="nx-content">
      <div style="display: flex;justify-content: space-between;">
        <div></div>
        <div>
          <el-button style="margin-bottom: 1rem;" class="btn-light-blue" @click="goBack">返回</el-button>
          <el-button style="margin-right: 2rem;margin-bottom: 1rem;" class="btn-light-blue"
            @click="handleAdd()">保存排程</el-button>

        </div>
      </div>
      <AddEditDialog :addEditId="addEditId" :addEditStatus="addEditStatus" :addEditIsDialog="addEditIsDialog">
      </AddEditDialog>
      <NxTable :table-cols="tableCols" :table-data="tableData" :pag-ination="pagination" class="table-wrap"
        @refresh="refresh">
        <template slot="status" slot-scope="scope">
          <el-switch @change="openStatus(scope.row)" v-model="scope.row.status" :active-value="1" :inactive-value="0">
          </el-switch>
        </template>
        <template slot="operation" slot-scope="scope">
          <span v-allow="'030105'" @click="handleDetail(scope.row)" class="nx-btn nx-edit">详情</span>
          <span v-allow="'030103'" @click="handleEdit(scope.row)" class="nx-btn nx-edit">编辑</span>
          <span v-allow="'030104'" @click="handleDelete(scope.row)" class="nx-btn nx-del">删除</span>
        </template>
      </NxTable>
    </div>

  </div>
</template>
<script>
import NxTable from '@/components/NxTable.vue'
import { Page } from '@/utils/pagination'
import AddEditDialog from './components/addEditDialog.vue'

import {

  getConfigAutoTaskConfigPreview
} from '@/api/system'
export default {

  components: {
    NxTable,
    AddEditDialog
  },
  // 表格数据
  data() {
    return {

      // 表格字段
      tableCols: [
        {
          label: '区域',
          prop: 'regionName',
          align: 'center',
        },
        {
          label: '类型',
          prop: 'typeName',
          align: 'center',
        },
        {
          label: '创建时间',
          prop: 'startTime',
          align: 'center',
        },
        {
          label: '结束时间',
          prop: 'endTime',
          align: 'center',
        },

        // {
        //   label: '操作',
        //   slot: 'operation',
        //   align: 'center',
        //   width: 180,
        //   fixed: 'right',
        // },
      ],
      tableData: [],
      pagination: new Page(),
      crumbsStatus: '', // 三级面包屑名称
      typeDialog: false,
      addEditIsDialog: false, // 添加编辑页面状态
      addEditStatus: 'add',
      addEditId: '', // 添加编辑rowid
      baseArray: [], // 角色集合
      companyArray: [], // 公司集合
      userType: '', // 用户类型（0超级管理员，1公司管理员，2公司员工）
      id: ''
    }
  },
  // 初始化加载
  mounted() {
    this.id = this.$route.query.id
    // this.getConfigAutoTaskConfigPreview()
    this.getList()
  },
  // 自定义方法
  methods: {
    submitForm() {

    },
    handleDetail(row) {
      // console.log(row);
      // <span v-if="scope.row.type == 0">进水控制箱</span>
      //     <span v-if="scope.row.type == 1">鱼池控制箱</span>
      //     <span v-if="scope.row.type == 2">尾水控制箱</span>
      // let type = ''
      // if (row.type == 0) {
      //   type = '进水控制箱'
      // } if (row.type == 1) {
      //   type = '鱼池控制箱'
      // } if (row.type == 2) {
      //   type = '尾水控制箱'
      // }
      // console.log(row);
      console.log(row)
      this.$router.push({
        path:
          `/schedule/scheduledetails?baseId=` +
          row.baseId +
          '&id=' +
          row.id +
          '&companyId=' +
          row.companyId,
      })
    },
    // 查询
    onSubmit() {
      this.pagination.pageNum = 1
      this.getList()
    },
    goBack() {
      this.$router.push({
        path: `/schedule/schedulingTool`,
        query: {
          activeName: 'fourth',

        },
      })
    },
    // 分页查询
    refresh(val) {
      this.searchForm.pageNum = val.pageNum
      this.searchForm.pageSize = val.pageSize
      this.getList()
    },
    // 重置
    resetForm() {
      this.searchForm = {
        pageNum: 1,
        pageSize: 10,
        baseId: '',
        code: '',
        companyId: '',
        deviceStatus: '',
        name: '',
        tailWaterModel: '',
        type: '',
      }

      this.onSubmit()
    },
    // 查询列表
    getList() {
      getConfigAutoTaskConfigPreview({ id: this.id }).then((res) => {
        if (res.code == 200) {
          this.tableData = res.data

          this.pagination.count = res.total
        }
      })
    },
    // 删除
    handleDelete(row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          delConfigFishpondModel({ id: row.id }).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: 'success',
                message: res.msg,
              })
              this.getList()
            }
          })
        })
        .catch((err) => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },
    // 添加
    handleAdd() {
      this.addEditId = ''
      this.addEditStatus = 'add'
      this.addEditIsDialog = true
    },
    // 编辑
    handleEdit(row) {
      this.addEditId = row.id + ''
      this.addEditStatus = 'edit'
      this.addEditIsDialog = true
    },
    // 编辑添加取消关闭
    closeAddEdit() {
      this.addEditIsDialog = false
    },
    // 面包屑
    crumbsClick() {
      this.typeDialog = false
    },
    // 启用、禁用
    handleStatus(row) {
      openOrCloseSysUser({ id: row.id }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: 'success',
            message: res.msg,
          })
          this.getList()
        }
      })
    },
    // 用户类型切换
    typeChange() {
      this.searchForm.companyId = ''
      this.companyArray = []

      this.searchForm.roleId = ''
      this.baseArray = []

      // 获取公司列表
      this.getCompanyInfoTree()

      // 查询
      this.onSubmit()
    },
    // 获取公司列表
    // getCompanyInfoTree() {
    //   if (this.searchForm.userType == 0) {
    //     // 超级管理员，公司只有一个总公司
    //     getCompanyInfoTree().then((res) => {
    //       if (res.code == 200) {
    //         this.companyArray = res.data
    //       }
    //     })
    //   } else {
    //     getCompanyInfoTree({ id: 0 }).then((res) => {
    //       if (res.code == 200) {
    //         this.companyArray = res.data
    //       }
    //     })
    //   }
    // },
    // 公司下拉切换
    changeTreeItem(val) {
      if (val) {
        this.searchForm.companyId = val[val.length - 1]
      } else {
        this.searchForm.companyId = ''
      }

      this.searchForm.baseId = ''
      this.baseArray = []

      this.getList()

      // 获取角色列表
      this.getSysCompanyBases()
    },
    // 获取角色列表
    // getSysCompanyBases() {
    //   if (
    //     this.searchForm.companyId === '' ||
    //     this.searchForm.companyId == null
    //   ) {
    //     return
    //   }

    //   getSysCompanyBases({ id: this.searchForm.companyId }).then((res) => {
    //     if (res.code == 200) {
    //       this.baseArray = res.data
    //     }
    //   })
    // },
  },
}
</script>
<style lang="less" scoped>
.main-breadcrumb {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 76px;
  border-bottom: solid 20px #f2f2f2;
  padding-left: 20px;

  .main-breadcrumb-wrap {
    font-size: 16px;
    line-height: 68px;

    .main-breadcrumb-home {
      cursor: pointer;
      color: #666666;
      font-weight: bold;
    }

    .main-breadcrumb-sp {
      color: #666666;
      font-weight: bold;
    }
  }
}
</style>
